using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TestTools.Common;
using Microsoft.VisualStudio.TestTools.Tips.TuipPackage;

namespace NUnitForVSTS.NUnitTest
{
	[Guid("E4BCCC7F-16A9-4e13-B2A2-20444D70F2B5")]
	internal class NUnitTestResultViewWindow:ToolWindowPane
	{
		private DetailedResultsControl _resultControl;
		private TestResult _result;

        /// <summary>
        /// Initializes a new instance of the <see cref="NUnitTestResultViewWindow"/> class.
        /// </summary>
		public NUnitTestResultViewWindow() : base(NUnitTestPackage.Instance as IServiceProvider)
		{
		}

        /// <summary>
        /// Gets the window to display the results.
        /// </summary>
        /// <value>The window.</value>
		public override IWin32Window Window
		{
			get
			{
				if (_resultControl == null)
					_resultControl = new DetailedResultsControl();
				return _resultControl;
			}
		}

        /// <summary>
        /// Loads the result.
        /// </summary>
        /// <param name="testResult">The test result.</param>
		public void LoadResult(TestResult testResult)
		{
            if (_resultControl == null)
            {
                _resultControl = new DetailedResultsControl();
            }

            if (_result != null && _result.Id.ExecutionId.Id == testResult.Id.ExecutionId.Id)
            {
                return;
            }

			_result = (TestResult) testResult.Clone();
			_resultControl.Init(testResult, NUnitTestPackage.Instance, this, null);
		}
	}
}
